﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI.WebControls;
using NTQOnlineExam.Services.CommandService.Payment;
using NTQOnlineExam.Services.Models;
using NTQOnlineExamFrontend.Models;

namespace NTQOnlineExamFrontend.Controllers
{
    public class PaymentController : Controller
    {
        private readonly IPaymentCommandService _paymentCommandService;

        public PaymentController(IPaymentCommandService paymentCommandService)
        {
            _paymentCommandService = paymentCommandService;
        }

        public ActionResult ProcessSuccessPayment()
        {
            var command = new DoExpressCheckoutCommand()
            {
                SuccessUrl = Request.QueryString["successUrl"],
                CancelUrl = Request.QueryString["cancelUrl"],
                Token = Request.QueryString["token"],
                PayerId = Request.QueryString["payerId"],
                Total = Request.QueryString["total"],
                OrderId = Request.QueryString["orderId"],
                Currency = Request.QueryString["ccCode"]
            };
            string message;
            if (_paymentCommandService.DoExpressCheckout(command, out message))
            {
                return Redirect(message);
            }
            return new EmptyResult();
        }
    }
}
